package eai.tp1.core.source;

import java.util.regex.Pattern;

/**
 * This class follows the design pattern Factory Method. It is the
 * implementation of a web page source, specifying how to extract the data from
 * the web page http://www.dpreview.com
 * 
 * @author Joel
 * 
 */
public class DPreviewSource implements IWebPageSource {

	@Override
	public String getBrandLink(String brand) {
		return "http://www.dpreview.com/reviews/specs/" + brand + "/";
	}

	@Override
	public Pattern getDate() {
		// TODO Auto-generated method stub
		return Pattern.compile("Announced\\s+(\\d\\d-\\w\\w\\w-\\d\\d)");
	}

	@Override
	public Pattern getDigitalCameraList() {

		return Pattern
				.compile("class=tdcontentsm.*?<a[^>]*href=\"(/reviews/specs/[^\"]*\\.asp)\"");
	}

	@Override
	public Pattern getEffectivePixels() {
		// TODO Auto-generated method stub
		return Pattern
				.compile("<a href=\"javascript:help_popup\\('effective pixels'\\)\">.*?<td class=\"tdcontentsm\">(.*?)<");
	}

	@Override
	public Pattern getImageLink() {
		// TODO Auto-generated method stub
		return Pattern.compile("<td class=\"tdlabelproduct\">.*?src=\"(.*?)\"");
	}

	@Override
	public Pattern getImageRatio() {
		// TODO Auto-generated method stub
		return Pattern
				.compile("<a href=\"javascript:help_popup\\('aspect ratio'\\)\">.*?<td class=\"tdcontentsm\">(.*?)</td>");
	}

	@Override
	public Pattern getIsoRating() {
		// TODO Auto-generated method stub
		return Pattern
				.compile("<a href=\"javascript:help_popup\\('sensitivity'\\)\">.*?<td class=\"tdcontentsm\">(.*?)<");
	}

	@Override
	public Pattern getMaxRes() {
		// TODO Auto-generated method stub
		return Pattern
				.compile("Max resolution.*?<td class=\"tdcontentsm\">(.*?)<");
	}

	@Override
	public Pattern getMaxShutter() {
		// TODO Auto-generated method stub
		return Pattern
				.compile("Max shutter.*?<td class=\"tdcontentsm\">(.*?)<");
	}

	// (\\s*(\\d+\\s*x\\s*\\d+)\\s*,*)*
	@Override
	public Pattern getMinRes() {
		// TODO Auto-generated method stub
		return Pattern
				.compile("Low resolution.*?<td class=\"tdcontentsm\">(.*?)<");
	}

	@Override
	public Pattern getMinShutter() {
		return Pattern
				.compile("Min shutter.*?<td class=\"tdcontentsm\">(.*?)<");
	}

	@Override
	public Pattern getName() {
		return Pattern.compile("class=\"tdlabelproduct\">([^<]+)<");
	}

	@Override
	public Pattern getReviewLink() {
		// TODO Auto-generated method stub
		return Pattern
				.compile("More information.*?<a href=\"/reviews/(.*?)\"\\s*class=\"reviewlink\">");
	}

	@Override
	public Pattern getSensorSize() {
		// TODO Auto-generated method stub
		return Pattern
				.compile("<a href=\"javascript:help_popup\\('sensor sizes'\\)\">.*?<td class=\"tdcontentsm\">(.*?)<.*?>(.*?)<");
	}

	@Override
	public String getRootLink() {
		return "http://www.dpreview.com";
	}

	@Override
	public Pattern getDescription() {
		// TODO Auto-generated method stub
		return Pattern
				.compile("<div class=\"description\">\\s*<p>\\s*(.*?)\\s*</p>");
	}

}
